package edu.houzi;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "Demo01Servlet" , urlPatterns = "/demo01")
public class Demo01Servlet implements Servlet {

//    private List<String> list = new ArrayList<>();
    // 体会到此变量为共享资源
    private int count = 0;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
//        list.add("This is init data ...");
        count ++;
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse)
            throws ServletException, IOException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
        String requestedSessionId = httpServletRequest.getRequestedSessionId();
        System.out.println("print session id : "+ requestedSessionId );

        count--;

//        httpServletResponse.getWriter().write("list size : "+list.size()+" \n ");
//        httpServletResponse.getWriter().write(" Print count : "+count+" \n ");
        httpServletResponse.setContentType("text/html");
        httpServletResponse.setCharacterEncoding("utf-8");
        httpServletResponse.getWriter().print("<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
                "    <title>calculator</title>\n" +
                "\n" +
                "</head>\n" +
                "<body>\n" +
                "    <div id=\"app\">\n" +
                "      \n" +
                "      <h1>\n" +
                "          <ul>\n" +
                "              <li>v-show 实质为改变样式，即style: dispalay</li>\n" +
                "              <li>v-if 实质为操作dom</li>\n" +
                "              <li>v-bind 操作属性绑定</li>\n" +
                "          </ul>\n" +
                "      </h1>\n" +
                "</body>\n" +
                "</html> ");


    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
